﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HeresyManager.Comunication;

namespace HeresyManager.Careers
{
    [Serializable]
    public class Scum : Career
    {
        private Skill[] skills;
        private Talent[] talents;

        public override string Name
        {
            get { return "Scum"; }
        }

        public override IEnumerator<Comunication.Comunicator> Acire(Character c)
        {
            List<Skill> skillList = new List<Skill>();

            skillList.Add(new Skills.SpeakLanguages.SpeakLanguageLowGothic(Skill.SkillLevel.Skilled));
            skillList.Add(new Skills.Blather(Skill.SkillLevel.Skilled));
            skillList.Add(new Skills.Deceive(Skill.SkillLevel.Skilled));
            skillList.Add(new Skills.Awareness(Skill.SkillLevel.Skilled));
            skillList.Add(new Skills.CommonLores.CommonLoreImperium(Skill.SkillLevel.Skilled));
            var chooseSkill = new Comunication.ChooseOne<Skill>("Choose one", new Skills.Charm(Skill.SkillLevel.Skilled), new Skills.Dodge(Skill.SkillLevel.Skilled));

            while (chooseSkill.SelectedValue == null)
                yield return chooseSkill;
            skillList.Add(chooseSkill.SelectedValue);

            skills = skillList.ToArray();

            foreach (var s in skills)
            {
                var en = c.AddSkill(s, this);
                while (en.MoveNext())
                    yield return en.Current;
            }




            List<Talent> talentList = new List<Talent>();
            var choose = new ChooseOne<Talent>("Choose One", new Talents.Ambidextrous(), new Talents.Unremarkable());
            talentList.Add(new Talents.WeaponTraining.BasicWeaponTrainingSP());
            talentList.Add(new Talents.WeaponTraining.MeleeWeaponTrainingPrimitive());
            talentList.Add(new Talents.WeaponTraining.BasicWeaponTrainingSP());

            while (choose.SelectedValue == null)
                yield return choose;
            talentList.Add(choose.SelectedValue);



            talents = talentList.ToArray();

            foreach (var s in talents)
            {
                var en = c.AddTalent(s, this);
                while (en.MoveNext())
                    yield return en.Current;
            }

        }

        public override void DeAcire(Character c)
        {
            foreach (var s in skills)
            {
                c.RemoveSkill(s, this);
            }

            foreach (var item in talents)
            {
                c.RemoveTalent(item, this);
            }
            this.talents = null;
        }

        public override Rank[] Ranks
        {
            get { return new Rank[] { }; }
        }

        public override BackgroundPackage[] BackgroundPackages
        {
            get { return new BackgroundPackage[] { new TheBeastSlaver(), new ColdGuildCourier(), new TheBrotherhoodofThollos() }; }
        }


        #region BackgroundPackges

        [Serializable]
        private class TheBeastSlaver : BackgroundPackage
        {

            private Talent[] talents;

            private int coruption;
            private Skill skill;

            public override string Name
            {
                get { return "The Beast Slaver"; }
            }

            public override int Cost
            {
                get { return 100; }
            }

            public override bool IsPreconditionSattisfied(Character c)
            {
                return base.IsPreconditionSattisfied(c) && c.HomeWorld is HomeWorlds.FeralWorld || c.HomeWorld is HomeWorlds.HiveWorld || c.HomeWorld is HomeWorlds.ImperialWorld;
            }

            public override IEnumerator<Comunicator> Accire(Character c)
            {
                var en = base.Accire(c);
                while (en.MoveNext())
                    yield return en.Current;


                var com = new Comunication.ChooseOne<Skill>("Choose One", new Skills.ForbiddenLores.ForbiddenLoreMutants(Skill.SkillLevel.Skilled), new Skills.ScholasticLores.ScholasticLoreBeasts(Skill.SkillLevel.Skilled));
                while (com.SelectedValue == null)
                    yield return com;
                skill = com.SelectedValue;
                en = c.AddSkill(skill, this);
                while (en.MoveNext())
                    yield return en.Current;


                talents = new Talent[] { new Talents.WeaponTraining.MeleeWeaponTrainingShock(), new Talents.Peers.PeerUnderworld() };
                foreach (var s in talents)
                {
                    en = c.AddTalent(s, this);
                    while (en.MoveNext())
                        yield return en.Current;
                }

                var rolDie = new RoleDice("Coruption", Dice.D5);
                while (rolDie.Value == -1)
                    yield return rolDie;
                coruption = rolDie.Value;
                c.CorruptionPoints += coruption;
            }

            public override void DeAccire(Character c)
            {
                base.DeAccire(c);
                foreach (var s in talents)
                {
                    c.RemoveTalent(s, this);
                }
                c.RemoveSkill(skill, this);
                c.CorruptionPoints -= coruption;

            }
        }

        [Serializable]
        private class ColdGuildCourier : BackgroundPackage
        {

            private Talent[] talents;


            public override string Name
            {
                get { return "Cold Guild Courier"; }
            }

            public override int Cost
            {
                get { return 100; }
            }

            public override bool IsPreconditionSattisfied(Character c)
            {
                return base.IsPreconditionSattisfied(c) && c.HomeWorld is HomeWorlds.VoidBorn;
            }

            public override IEnumerator<Comunicator> Accire(Character c)
            {
                var en = base.Accire(c);
                while (en.MoveNext())
                    yield return en.Current;

                c.Per += 5;
                c.T -= 5;


                talents = new Talent[] { new Talents.ConcealedCavity(), new Talents.Peers.PeerVoidBorn(), new Talents.Talented(new Skills.Concealment(Skill.SkillLevel.Skilled)) };
                foreach (var s in talents)
                {
                    en = c.AddTalent(s, this);
                    while (en.MoveNext())
                        yield return en.Current;
                }

            }

            public override void DeAccire(Character c)
            {
                base.DeAccire(c);
                c.Per -= 5;
                c.T += 5;
                foreach (var s in talents)
                {
                    c.RemoveTalent(s, this);
                }

            }
        }

        [Serializable]
        private class TheBrotherhoodofThollos : BackgroundPackage
        {

            private Talent[] talents;


            public override string Name
            {
                get { return "The Brotherhood of Thollos"; }
            }

            public override int Cost
            {
                get { return 200; }
            }

            public override bool IsPreconditionSattisfied(Character c)
            {
                return base.IsPreconditionSattisfied(c) && c.HomeWorld is HomeWorlds.VoidBorn;
            }

            public override IEnumerator<Comunicator> Accire(Character c)
            {
                var en = base.Accire(c);
                while (en.MoveNext())
                    yield return en.Current;

                c.WS += 3;
                c.T += 3;
                c.Fel -= 5;


                talents = new Talent[] { new Talents.StreetFighting(), new Talents.Peers.PeerUnderworld() };
                foreach (var s in talents)
                {
                    en = c.AddTalent(s, this);
                    while (en.MoveNext())
                        yield return en.Current;
                }

            }

            public override void DeAccire(Character c)
            {
                base.DeAccire(c);
                c.WS -= 3;
                c.T -= 3;
                c.Fel += 5;
                foreach (var s in talents)
                {
                    c.RemoveTalent(s, this);
                }

            }
        }
        #endregion


        public override int[] WeaponSkillCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] BalisticSkillCost
        {
            get { return new int[] { 100, 250, 500, 750 }; }
        }

        public override int[] StrengthCost
        {
            get { return new int[] { 500, 750, 1000, 2500 }; }
        }

        public override int[] ToughnessCost
        {
            get { return new int[] { 500, 750, 1000, 2500 }; }
        }

        public override int[] AgilityCost
        {
            get { return new int[] { 100, 250, 500, 500 }; }
        }

        public override int[] IntelligenceCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] PerceptionCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] WillpowerCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] FellowshipCost
        {
            get { return new int[] { 100, 250, 500, 750 }; }
        }
    }
}
